package com.ruoyi.cbs.contract.domain.vo;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import com.ruoyi.cbs.contract.domain.ContractorInsurance;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.StringUtils;
import lombok.Data;

import java.io.Serializable;
import java.util.Date;
import java.util.List;

/**
 * 承包商信息对象 cbs_contractor
 */
@Data
public class ContractorVo implements Serializable
{
    private static final long serialVersionUID = 1L;

    /** 承包商ID */
    @JsonSerialize(using = ToStringSerializer.class)
    private Long contractorId;
    /** 承包商名称 */
    private String contractorName;
    /** 统一社会信用代码 */
    private String contractorCode;
    /** 注册地址 */
    private String registerAddress;
    /** 实际办公地址 */
    private String officeAddress;
    /** 企业法人 */
    private String legalPerson;
    /** 注册资本 */
    private String registeredCapital;
    /** 联系人 */
    private String contactPerson;
    /** 联系电话 */
    private String contactPhone;
    /** 企业类型 */
    private String enterpriseType;
    /** 经营范围 */
    private String businessScope;
    /** 管理部门 */
    private String managementDept;
    /** 管理部门联系人 */
    private String managementPerson;
    /** 营业执照 */
    private String licenseFileId;
    /** 营业执照 */
    private String licenseFileUrl;
    /** 营业执照 */
    private String licenseFileName;
    /** 审核状态 */
    private String status;


    /** 保险名称 */
    private String insuranceName;
    /** 保险起始 */
    @JsonFormat(pattern = "yyyy-MM-dd")
    private String insuranceStartDate;
    /** 保险截止 */
    @JsonFormat(pattern = "yyyy-MM-dd")
    private String insuranceEndDate;
    /** 保险人数, 仅针对人身类保险（如施工人员意外险）必填，财产类保险（如工程一切险）可设为 NULL */
    private int insuredCount;
    /** 保险类型, 强制保险,自愿保险 */
    private String insuranceType;
    /** 保险单号 */
    private String insuranceNo;
    /** 承保保险公司 */
    private String insurer;

    private List<ContractorEquipmentVo> equipmentList;
    private List<ContractorPersonnelVo> personnelList;
    private List<ContractorDocumentVo> documentlList;

    public ContractorInsurance contractorVoToInsurance(ContractorVo contractorVo) {
        String insName = contractorVo.getInsuranceName();
        String insNo = contractorVo.getInsuranceNo();
        if (StringUtils.isEmpty(insName) || StringUtils.isEmpty(insNo)) {
            return null;
        }

        String startDate = contractorVo.getInsuranceStartDate();
        String endDate = contractorVo.getInsuranceEndDate();
        ContractorInsurance insurance = new ContractorInsurance();
        insurance.setContractorName(contractorVo.getContractorName());
        insurance.setName(contractorVo.getInsuranceName());
        insurance.setInsuranceNo(contractorVo.getInsuranceNo());
        insurance.setInsuredCount(contractorVo.getInsuredCount());
        insurance.setInsuranceType(contractorVo.getInsuranceType());
        insurance.setInsurer(contractorVo.getInsurer());
        insurance.setStart(DateUtils.parseDate(startDate));
        insurance.setEnd(DateUtils.parseDate(endDate));

        return insurance;
    }

}
